package com.tan.steamship.controller;

import com.tan.steamship.common.Result;
import com.tan.steamship.dto.ShipsDto;
import com.tan.steamship.service.ShipsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @description: 船信息
 * @author: longshifu
 * @time: 2025/1/20 14:51
 */
@RestController
@RequestMapping("/ships/v1")
public class ShipsController {
    @Autowired
    private ShipsService shipsService;

    @GetMapping("/list")
    public Result listShips(@RequestParam(value = "shipName", required = false) String shipName,
                            @RequestParam(value = "pageIndex", defaultValue = "1") int pageIndex,
                            @RequestParam(value = "pageSize", defaultValue = "10") int pageSize) {
        return Result.success(shipsService.listShips(shipName,pageIndex, pageSize));
    }

    @PostMapping("/saveOrUpdate")
    public Result saveOrUpdate(@RequestBody ShipsDto shipsDto) {
        shipsService.saveOrUpdate(shipsDto);
        return Result.success();
    }

    @GetMapping("/detail")
    public Result detail(@RequestParam("id") String id) {
        return Result.success(shipsService.detail(id));
    }

    @GetMapping("/delete")
    public Result delete(@RequestParam("id") String id) {
        shipsService.removeById(id);
        return Result.success();
    }

    @GetMapping("/list/shipName")
    public Result listShipName() {
        return Result.success(shipsService.listShipName());
    }
}
